﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HelloWord.aspx.cs" Inherits="BugSysSolution.PageTemplate.HelloWord" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Knockout.js"></script>
</head>
<body>
    <form data-bind="submit: addItem">New item:   
        <input data-bind='value: itemToAdd, valueUpdate: "afterkeydown"' />
        <button type="submit" data-bind="enable: itemToAdd().length > 0">Add</button>
        <p>Your items:</p>
        <select multiple="multiple" width="50" data-bind="options: items"></select>
    </form>
</body>
</html>
<script type="text/javascript">

    // event 需要bind  peotos 需要初始化
    var model = function (items)
    {
        if (items == null) {
            items = new Array();
        }
        this.items = ko.observableArray(items);
        this.itemToAdd = ko.observable("");
        this.addItem = function () {
            if (this.itemToAdd() != "") {
                this.items.push(this.itemToAdd());
            }
        }.bind(this);
    }
    ko.applyBindings(new model());
</script>
